package com.gugee.ins.data.blogger.es.controller;

import com.gugee.ins.data.blogger.es.core.MediaToEsService;
import com.xiguaji.boot.toolkit.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value = "to/es")
@Slf4j
public class ToEsController {
    @Autowired
    MediaToEsService mediaToEsService;

    @RequestMapping(value = "/media/{uid}",method = RequestMethod.GET)
    public String updateBloggerMediaInfo(@PathVariable long uid){
        Map<String,Object> ret = new HashMap();
        ret.put("code",200);
        ret.put("msg","执行成功！");

        try{
            mediaToEsService.handler(uid);
        }catch (Exception e){
            ret.put("code",-200);
            ret.put("msg","执行失败！");
            ret.put("error",e.getMessage());
            log.error("帖子同步到ES失败",e);
        }
        return JsonUtil.parseJson(ret);
    }
}
